package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageUsagerecordDto;
import com.itsq.pojo.dto.PageUsersDto;
import com.itsq.pojo.dto.UsageRecordEndDto;
import com.itsq.pojo.entity.Car;
import com.itsq.pojo.entity.UsageRecord;
import com.itsq.pojo.entity.Users;
import com.itsq.service.resources.UsersService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-02-01
 */
@RestController
@RequestMapping("/users")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "用户信息模块")
public class UsersController  extends BaseController {

    @Autowired
    private UsersService usersService;

    @PostMapping("selUsersPageFront")
    @ApiOperation(value = "用户信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Users>> selUsersPageFront(@RequestBody PageUsersDto pageUsersDto){
        Page<Users> UsersPage = usersService.selUsersPageFront(pageUsersDto);
        return Response.success(UsersPage);
    }

    @PostMapping("selUsersPageAfter")
    @ApiOperation(value = "管理员——用户信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Users>> selUsersPageAfter(@RequestBody PageUsersDto pageUsersDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Users> UsersPage = usersService.selUsersPageAfter(pageUsersDto);
        return Response.success(UsersPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——用户信息模块添加", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Users users){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(usersService.insert(users));
    }

    @PostMapping("insertAfter")
    @ApiOperation(value = "用户信息模块前台添加", notes = "", httpMethod = "POST")
    public Response<Integer> insertAfter(@RequestBody Users users){
        return Response.success(usersService.insert(users));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——用户信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Users users){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(usersService.update(users));
    }

    @PostMapping("selUsersById")
    @ApiOperation(value = "管理员——用户信息模块id查询", notes = "", httpMethod = "POST")
    public Response<Users> selUsersById(Integer id){
        return Response.success(usersService.selUsersById(id));
    }

    @PostMapping("selUsersList")
    @ApiOperation(value = "管理员——用户信息模块list查询", notes = "", httpMethod = "POST")
    public Response<List<Users>> selUsersList(){
        return Response.success(usersService.selUsersList());
    }

    @PostMapping("selUsersStateList")
    @ApiOperation(value = "用户信息模块注册查询", notes = "", httpMethod = "POST")
    public Response<List<Users>> selUsersStateList(){
        return Response.success(usersService.selUsersStateList());
    }
}

